import http from ".."
import type { CustomSuccessData, Dashboard, DataParam, LoginParam, LoginResult } from "@/api/types"

// export const login= async(loginParam:LoginParam):Promise<CustomSuccessData<LoginResult>>=>{
//   return new Promise((resolve, reject) => {
//       uni.request({
//           url: import.meta.env.VITE_BASE_URL + '/login', // Developer server interface address
//           method: 'POST', // Request method
//           data: {
//               username:loginParam.username,
//               password:loginParam.password
//           },
//           success: (res:any) => {
//               // Received the callback function successfully returned by the developer server
//               resolve(res)
//           },
//           fail: (err) => {
//               // Interface call failure callback function
//               reject(err)
//           }
//       })
//   })
//     // const res = await http.reqPost<LoginResult>(
//     //     '/login',
//     //     {
//     //         username:loginParam.username,
//     //         password:loginParam.password
//     //     },
//     // )
//     // return res
// }
// : Promise<CustomSuccessData<LoginResult>>
export const login = async (loginParam: LoginParam) => {
    const res  = await uni.request({
        url: import.meta.env.VITE_BASE_URL + '/login',
        method: 'POST',
        header: {
            'Content-Type': 'application/json'
        },
        data: {
            username: loginParam.username,
            password: loginParam.password
        }
    });
    return res.data; // uni.request返回一个数组，第一个元素是错误信息，第二个元素是响应数据
}


export const dashboard=async(dataParam:DataParam):Promise<CustomSuccessData<Dashboard>>=>{
    const res = await http.reqPost<Dashboard>(
        '/dashboard',
        {
            startTime:dataParam.startDate,
            endTime:dataParam.endDate
        },
    )
    return res
}
